import type { AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios';
import type { RequestOptions, Result } from '/#/axios';

export interface CreateAxiosOptions extends AxiosRequestConfig {
  transform?: AxiosTransform;
  requestOptions?: RequestOptions;
}

export interface AxiosTransform {
  // 请求前处理配置
  beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig;
  // 处理响应数据
  transformResponseHook?: (res: AxiosResponse<Result>, options: RequestOptions) => any;
  // 请求失败处理
  requestCatchHook?: (e: Error, options: RequestOptions) => Promise<any>;

  // 请求之前的拦截器
  requestIntercepters?: (config: AxiosRequestConfig, options: CreateAxiosOptions) => AxiosRequestConfig;

  //请求之后的拦截器
  responseIntercepters?: (res: AxiosResponse<any>) => AxiosResponse<any>;

  //请求之前的拦截器错误处理
  requestInterceptersCatch?: (error: Error) => void;

  //请求之后的拦截器错误处理
  responseInterceptersCatch?: (axiosInstance: AxiosInstance, error: Error) => void;
}
